﻿namespace FFF.Test.Application.Repositories.CF
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using Abp.Application.Services.Dto;
    using Abp.AutoMapper;
    using FFF.Test.Entity.CF;
    using FFF.Test.Entity.FW;
    using FFF.Test.Entity.FW.View;
    using Ydm.Extensions;

    /// <summary>
    /// 获取业务参数信息(于大明)输入dto
    /// </summary>
    public class GetConfigInfoInDto
    {
        /// <summary>
        /// 参数范围GUID
        /// </summary>
        public Guid? BizOptionScopeGUID { get; set; }
    }

    /// <summary>
    /// 获取业务参数信息(于大明)输出dto
    /// </summary>
    public class GetConfigInfoOutDto
    {
        /// <summary>
        /// 输出dtos
        /// </summary>
        public List<GetConfigInfoDto> Dtos { get; set; }

    }

    /// <summary>
    /// 获取业务参数信息(于大明)输出dto
    /// </summary>
    public class GetConfigInfoDto
    {
        /// <summary>
        /// 分组的名称
        /// </summary>
        public string BizConfigGroupName { get; set; }

        /// <summary>
        /// 分组GUID
        /// </summary>
        public Guid BizConfigGroupGUID { get; set; }

        /// <summary>
        /// 选择集合
        /// </summary>
        public List<GetConfigInfoItem> Items { get; set; }

    }

    /// <summary>
    /// 配置参数Dto
    /// </summary>
    [AutoMapFrom(typeof(ViewFWBizConfigOption))]
    public class GetConfigInfoItem
    {
        /// <summary>
        /// 配置类业务参数GUID
        /// </summary>
        [Display(Name = "配置类业务参数GUID", Description = "配置类业务参数GUID")]
        [Column("BizConfigOptionGUID")]
        public Guid Id { get; set; }

        /// <summary>
        /// 配置类业务参数分组GUID
        /// </summary>
        [Display(Name = "配置类业务参数分组GUID", Description = "配置类业务参数分组GUID")]
        [Column("BizConfigGroupGUID")]
        public Guid? BizConfigGroupGUID { get; set; }

        /// <summary>
        /// 配置类业务参数名称
        /// </summary>
        [Display(Name = "配置类业务参数名称", Description = "配置类业务参数名称")]
        [Column("BizConfigOptionName")]
        [StringLength(128)]
        public string BizConfigOptionName { get; set; }

        /// <summary>
        /// 业务参数类型(1,文本框;2,数字框;3,单选;4,多选;5,日期;6,下拉)
        /// </summary>
        [Display(Name = "业务参数类型(1,文本框;2,数字框;3,单选;4,多选;5,日期;6,下拉)", Description = "业务参数类型(1,文本框;2,数字框;3,单选;4,多选;5,日期;6,下拉)")]
        [Column("BizOptionType")]
        public CFBizConfigOptionBizOptionTypeEnum? BizOptionType { get; set; }

        /// <summary>
        /// 如果是checkbox和下拉那么需要配置对应的值逗号分割
        /// </summary>
        [Display(Name = "如果是checkbox和下拉那么需要配置对应的值逗号分割", Description = "如果是checkbox和下拉那么需要配置对应的值逗号分割")]
        [Column("BizOptions")]
        [StringLength(2048)]
        public string BizOptions { get; set; }

        /// <summary>
        /// 参数的值多个以,分割
        /// </summary>
        [Display(Name = "参数的值多个以,分割", Description = "参数的值多个以,分割")]
        [Column("BizOptionValue")]
        [StringLength(2048)]
        public string BizOptionValue { get; set; }

        /// <summary>
        /// 参数的排序
        /// </summary>
        [Display(Name = "参数的排序", Description = "参数的排序")]
        [Column("BizOptionOrder")]
        [StringLength(72)]
        public string BizOptionOrder { get; set; }

        /// <summary>
        /// 参数范围GUID有可能集团有可能公司
        /// </summary>
        [Display(Name = "参数范围GUID有可能集团有可能公司", Description = "参数范围GUID有可能集团有可能公司")]
        [Column("BizOptionScopeGUID")]
        public Guid? BizOptionScopeGUID { get; set; }

        /// <summary>
        /// 字典的Code
        /// </summary>
        [Display(Name = "字典的Code", Description = "字典的Code")]
        [Column("BizOptionCode")]
        [StringLength(512)]
        public string BizOptionCode { get; set; }

        /// <summary>
        /// 参数备注
        /// </summary>
        [Display(Name = "参数备注", Description = "参数备注")]
        [Column("BizOptionRemark")]
        [StringLength(-1)]
        public string BizOptionRemark { get; set; }

        /// <summary>
        /// 分组名称
        /// </summary>
        [Display(Name = "分组名称", Description = "分组名称")]
        [Column("BizConfigGroupName")]
        [StringLength(64)]
        public string BizConfigGroupName { get; set; }

        /// <summary>
        /// 值的集合
        /// </summary>
        public string[] Values
        {
            get
            {
                var ary = this.BizOptionValue?.Split(",");
                return ary;
            }
        }

        /// <summary>
        /// option的集合
        /// </summary>
        public List<GetConfigInfoOptionItem> Options
        {
            get
            {
                List<GetConfigInfoOptionItem> items = new List<GetConfigInfoOptionItem>();
                if (!this.BizOptions.IsNullOrEmpty())
                {
                    var arys = this.BizOptions?.Split(";");
                    foreach (var ary in arys)
                    {
                        var arySplit = ary.Split(",");
                        GetConfigInfoOptionItem item = new GetConfigInfoOptionItem()
                        {
                            Value = string.Empty,
                            Name = string.Empty
                        };
                        if (arySplit.Length == 1)
                        {
                            item = new GetConfigInfoOptionItem()
                            {
                                Value = arySplit[0],
                                Name = arySplit[0]
                            };
                        }

                        if (arySplit.Length > 1)
                        {
                            item = new GetConfigInfoOptionItem()
                            {
                                Value = arySplit[0],
                                Name = arySplit[1]
                            };
                        }

                        items.Add(item);
                    }
                }

                return items;
            }
        }
    }

    /// <summary>
    /// optionItem的集合
    /// </summary>
    public class GetConfigInfoOptionItem
    {
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; }
    }
}
